package com.example.toy.core.system;

import com.example.toy.ToySystem;
import com.example.toy.ToySystemCache;
import com.example.toy.core.conf.ToySystemConfig;

import java.io.Closeable;

/**
 * AbstractToySystem
 *
 * @author shenbing
 * @date 2021/12/23
 */
public abstract class AbstractToySystem implements ToySystem, Closeable {
  protected final ToySystemConfig config;

  public AbstractToySystem(ToySystemConfig config) {
    this.config = config;
    ToySystemCache.register(config.getSystemName(), this);
  }

  @Override
  public void close() {
    ToySystemCache.unregister(config.getSystemName());
  }

  @Override
  public String toString() {
    return "ToySystem{name = "
        + config.getSystemName()
        + ", type = "
        + config.getSystemType()
        + "}";
  }
}
